<template>
	<view>
		<label for="a">
			<view class="box">

				<!-- <navigator url="/pages/search/search"> -->
				<image src="../../static/images/sousuo.png" mode=""></image>
				<view class="content">
					<input type="text" value="" class="search-box" placeholder="搜索地区" @input="handleInput" id="a" />
				</view>

				<!-- </navigator> -->
			</view>
		</label>
	</view>
</template>
<script>
	import {
		citySeach
	} from "@/utils/api.js"

	import {
		eventBus
	} from '@/main.js';

	export default {
		data() {
			return {
				value: "",
				timer: null
			}
		},
		methods: {
			//输入框防抖
			handleInput(e) {
				if (this.timer !== null) {
					clearTimeout(this.timer);
				}
				this.timer = setTimeout(async () => {
					console.log("触发了一次");
					let res = await citySeach({
						location: e.detail.value,
						key: "2d5557cc8feb46749ee7b458cc0d2e3a",
					})
					this.$emit('getPosition', res.location[0].id)

					this.$emit('getLocation', [res.location[0].lon, res.location[0].lat])

					this.timer = null
				}, 500)
			}

		}
	}
</script>
<style lang="scss">
	.box {
		padding: 20rpx;
		background: #eee;
		border-radius: 20rpx;
		margin: 0 20rpx;
		overflow: hidden;

		image {
			padding-top: 25rpx;
			float: left;
			width: 30rpx;
			height: 30rpx;
		}

		.content {
			float: left;
			padding-left: 10rpx;
			font-size: 30rpx;

			input {
				width: 620rpx;
				height: 70rpx;
			}

		}
	}
</style>